<template>
    <div>
        <!--卡片-->
        <el-card class="box-card">
            <!--定义面包屑-->
            <el-breadcrumb separator=">">
                <el-breadcrumb-item :to="{ path: '/master' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>营销管理</el-breadcrumb-item>
                <el-breadcrumb-item>客服问答</el-breadcrumb-item>
            </el-breadcrumb>
            <el-divider></el-divider>
            <!--表单的搜索框
                 :model="双向绑定表单的数据"
            -->
            <el-form :inline="true" :model="cusIssFormData"  class="demo-form-inline">
                <el-form-item>
                    <el-input v-model="cusIssFormData.submodule" placeholder="请输入模块"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="initCusIss()">查询</el-button>
                    <el-button type="primary" @click="insertCusIss">添加</el-button>
                </el-form-item>
            </el-form>

            <!--数据表格-->
            <template>
                <el-table
                        :data="tableData"
                        :border="true"
                        stripe
                        style="width: 100%">
                    <el-table-column
                            prop="id"
                            label="编号"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="submodule"
                            label="所属模块"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="question"
                            label="问题">
                    </el-table-column>
                    <el-table-column
                            prop="answer"
                            label="答案">
                    </el-table-column>

                    <el-table-column
                            prop="addtime"
                            label="添加时间">
                    </el-table-column>

                    <el-table-column label="操作">
                        <template slot-scope="scope">
                            <el-button type="primary" icon="el-icon-edit" @click="selById(scope.row.id)" circle></el-button>
                            <el-button type="danger" icon="el-icon-delete" @click="del(scope.row.id)" circle></el-button>
                        </template>
                    </el-table-column>
                </el-table>

                <!-- 分页-->
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="currentPage"
                        :page-sizes="[5, 10, 15, 20]"
                        :page-size="pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </template>
        </el-card>

        <!--        更新信息表单-->
        <el-dialog
                title="添加客服问答信息"
                :visible.sync="editCusIss"
                width="30%"
                :before-close="cha"
        >
            <!--          model表单数据-->
            <el-form  label-width="80px" :model="cusIssForm" :rules="cusIssFormRules" ref="cusIssFormRef">
<!--                <el-form-item label="所属模块" prop="submodule">-->
<!--                    <el-input v-model="cusIssForm.submodule" clearable></el-input>-->
<!--                </el-form-item>-->

                <el-form-item label="所属模块"  prop="submodule">
                    <el-select v-model="cusIssForm.submodule" placeholder="请选择模块">
                        <el-option label="黑铁" value="黑铁"></el-option>
                        <el-option label="铂金" value="铂金"></el-option>
                        <el-option label="王者" value="王者"></el-option>
                        <el-option label="其他" value="其他"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="问题" prop="question">
                    <el-input v-model="cusIssForm.question" clearable></el-input>
                </el-form-item>
                <el-form-item label="回答" prop="answer">
                    <el-input v-model="cusIssForm.answer" clearable></el-input>
                </el-form-item>

                <el-form-item label="添加时间" prop="addtime">
                    <el-date-picker
                            v-model="cusIssForm.addtime"
                            type="datetime"
                            placeholder="选择日期时间">
                    </el-date-picker>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                        <el-button @click="qx">取 消</el-button>
                        <el-button type="primary" @click="editCusIssBtn">确 定</el-button>
                    </span>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        name: "CustoIssues",
        data(){
            return {
                //条件搜索对象
                cusIssFormData:{},
                //表格数据
                tableData:[],
                //每页显示的条数
                pageSize: 5,
                //当前的显示的页码
                currentPage:1,
                //总条数
                total:0,
                //更新用户弹出框显示状态
                editCusIss:false,
                //添加用户表单信息
                cusIssForm:{
                    submodule:"",
                    question:"",
                    answer:"",
                    addtime:"",

                },
                // 用户表单校验数据:
                cusIssFormRules:{
                    submodule:[{required:true,message:"所属模块不可为空",trigger:'blur'}],
                    question:[{ required: true, message: '问题不可为空',trigger: 'blur'}],
                    answer:[{ required: true, message: '答案不可为空',trigger: 'blur'}],
                    addtime:[{ required: true, message: '添加日期不可为空',trigger: 'blur'}],


                },
            }
        },
        created() {
            //获取用户的信息
            this.initCusIss();

        },
        methods:{
            initCusIss(){
                //get方式不支持json数据
                var that=this;
                this.$http.post(`/marketing/issues/selectCustIssues/${this.currentPage}/${this.pageSize}`,this.cusIssFormData).then(function (re) {
                    that.tableData=re.data.result.records;
                    that.total=re.data.result.total;

                })
            },
            //当改变没有显示的条数时触发该方法
            handleSizeChange(v){
                this.pageSize=v
                this.initCusIss();
            },
            //切换页码时触发该方法
            handleCurrentChange(v){
                this.currentPage=v
                this.initCusIss();
            },
            //点击添加按钮
            insertCusIss(){
                this.editCusIss=true;
                //将form表单数据清空,以防止修改时数据回显后表单中有数据冗余
                this.cusIssForm={};

            },
            //关闭弹框
            handleClose(formName) {
                this.$refs[formName].resetFields();
                this.editCusIss= false;


            },
            //改状态
            // switchStatus(id,status){
            //     this.$http.put(`/system/user/up/${id}/${status}`).then(function (re) {
            //
            //     })
            // },
            // showUserRole(id){
            //     this.fenRoleDialog=true;
            //     this.id=id;
            //     var that=this;
            //
            //     this.$http.get(`/system/role/sel/${id}`).then(function (resp) {
            //         that.roleAll=resp.data.result.roleAll;
            //         that.userRole=resp.data.result.userRole;
            //         console.log(that.userRole)
            //     })
            // },
            //更新用户 ,弹出框确定按钮事件
            editCusIssBtn(){
                var that=this;
                this.$refs.cusIssFormRef.validate((valid) => {
                    if (valid){
                        if(this.cusIssForm.id!=null) {
                            this.$http.put(`/marketing/issues/updateCustIssues`,this.cusIssForm).then(function (r) {
                                that.$message.success(r.data.message);
                                that.editCusIss=false;
                                that.initCusIss();
                            })
                        }else{
                            this.$http.post(`/marketing/issues/insertCustIssues`,this.cusIssForm).then(function (r) {
                                that.$message.success(r.data.message);
                                that.editCusIss=false;
                                that.initCusIss();

                            })
                        }
                        this.$refs.cusIssFormRef.resetFields();
                    }
                })

            },

            //点击修改根据id进行回显
            selById(id){
                var that=this;
                this.editCusIss=true;
                this.$http.get(`/marketing/issues/byId/${id}`).then(function (r) {
                    that.cusIssForm=r.data.result.custIssues;
                })
            },
            del(id){
                var that=this;
                this.$http.delete(`/marketing/issues/deleteCustIssues/${id}`).then(function (r) {
                    that.initCusIss();
                    // location.reload();
                })
                this.currentPage=1;
            },
            //弹出框的取消按钮,重置数据,关闭弹窗
            qx(){
                // this.$refs.cusIssFormRef.resetFields();
                this.editCusIss=false;
            },
            //×按钮
            cha(){
                this.$refs.cusIssFormRef.resetFields();
                this.editCusIss=false;
            },

        }
    }
</script>

<style scoped>

</style>